<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<?php
if(!isset($_SESSION)){
	session_start();
}

if(!isset($_SESSION["adminName"]) || (empty($_SESSION["adminName"]))){
	header ("Location: ../index.php");
}
?>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Edit Page</title>
    <link href="../../Styles/adminstype.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../js/admin_script.js"></script>
</head>
<body>
<?php
	$TenLSP = "";
	$BiXoa = "";
	$checked = "";
	$id = $_SESSION["edit"];
	
	if(empty($_REQUEST["btnSua"])){
		if($id != "") // kiem tra du lieu
		{
			$sql = "select * from loaisanpham where MaLoaiSanPham = $id";
				
			require_once "../database/DataProvider.php";
			$result =  DataProvider::ExecuteQuery($sql);
				
			if(!empty($result))
			{
				while ($row=mysql_fetch_array($result)){
					$TenLSP = $row["TenLoaiSanPham"];
					$BiXoa = $row["BiXoa"];
					$checked = ($row["BiXoa"] == 0 ? '' : 'checked');
				}	
			}
		}
	}
?>
<table>
	<tr class="boxContentTitle">
		<td>Sửa sản phẩm</td>
	</tr>
	<tr>
		<td>
			 <form action="resource/form_edit_category.php" method="post" name="form_edit_category">
				<table class="tableBoxView">
					<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Tên loại sản phẩm</td>
						<td><input type="text" maxlength="300" name="txtTen" id="txtTen" <?php echo("value='$TenLSP'");?>/></td>
					</tr>
					<tr>
						<td><td>
						<td>Bị xóa</td>
						<td><input type="checkbox" name="Xoa" value="Yes"<?php echo(" ");  echo($checked);?>></td>
					</tr>
					<tr>
						<td><td>
						<td></td>
						<td><input type="submit" name="btnSua" value="Save" onclick="return kiemTraTxt('txtTen')"/></td>
					</tr>
				</table>
			</form>
		</td>
	</tr>
	<tr>
		<td>
			<?php
			if(!empty($_REQUEST["btnSua"]))//có yeu cau sua
			{
				$ten = $_REQUEST["txtTen"];
				$xoa = 0;
				if(isset($_REQUEST["Xoa"]) && $_REQUEST["Xoa"] == "Yes"){
					$xoa = 1;
				}

				echo($xoa);
				if($ten != "") //  kiểm tra 
				{
					$sql = "UPDATE loaisanpham SET TenLoaiSanPham='" .$ten."', BiXoa=$xoa WHERE MaLoaiSanPham=$id";
					require_once "../../database/DataProvider.php";
					$result =  DataProvider::ExecuteQuery($sql);
					echo($result);
				}
				header ("Location: ../admin_manager_category.php");
			}
			?>
		</td>
	</tr>
</table>
</body>
</html>